//
//  NewLoveMarketingHomewController.m
//  HCNewGoldFinger
//
//  Created by 刘琛 on 2018/3/23.
//  Copyright © 2018年 zjhcsoftios. All rights reserved.
//

#import "NewLoveMarketingHomewController.h"
#import "NewHomeCarouselModel.h"
#import "NewLoveMarketingHomeModel.h"
#import "UIView+BlocksKit.h"
#import "TYCyclePagerView.h"
#import "TYPageControl.h"
#import "NewLoveMarketingTopCarouselCell.h"
#import "NewLoveMarketingMarkCell.h"
#import "NewLoveMarkingStatusCell.h"
#import "ZSBWorkOrderViewController.h"
#import "ErweimaViewController.h"
#import "UIBarButtonItem+BlocksKit.h"
#import "MJRefresh.h"
#import "UIColor+Ex.h"
#import "NirKxMenu.h"
#import "iSeeNetworkRequest.h"
#import "NetworkAddress.h"
#import "SVProgressHUD.h"
#import <MJExtension/MJExtension.h>
#import "UIViewController+GetBundle.h"
#import "NewHomeCustomerViewModel.h"
#import "NewMarketWebViewController.h"
#import <SDWebImage/SDWebImage.h>
#import "ISeeUserInfoModel.h"
#import "NewHomeWebViewController.h"
#import "NewOrdorListViewController.h"
#import "NSBundle+AssociatedBundle.h"
#import "ZPjiugonggeViewController.h"
#import <YYModel/NSObject+YYModel.h>
#define iSEESCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)

@interface NewLoveMarketingHomewController ()<TYCyclePagerViewDataSource, TYCyclePagerViewDelegate,NewLoveMarketingTopCarouselCellDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) NSMutableArray *carouseList;

@property (nonatomic, strong) NewLoveMarketingHomeModel *homeModel;

//首页轮播图
@property (nonatomic, strong) TYCyclePagerView *carousePageView;
@property (nonatomic, strong) TYPageControl *carousePageCtrl;
@property (weak, nonatomic) IBOutlet UIView *carouseBackView;

//中间标签列表
@property (nonatomic, strong) TYCyclePagerView *markPageView;
@property (nonatomic, strong) TYPageControl *markPageCtrl;
@property (weak, nonatomic) IBOutlet UIView *markBackView;
@property (nonatomic, strong) UICollectionView *markCollectionView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *statusBackViewHeight;
@property (weak, nonatomic) IBOutlet UIView *statusBackView;
@property (nonatomic, strong) UICollectionView *statusView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *buttomViewHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *otherEnterViewHeight;
//统计报表
@property (weak, nonatomic) IBOutlet UIView *statisticalReport;
//微培训
@property (weak, nonatomic) IBOutlet UIView *smallTraining;
//易问
@property (weak, nonatomic) IBOutlet UIView *easyAsking;

//@property (nonatomic, strong) CommissionInfoModel *rewardModel;
@property (weak, nonatomic) IBOutlet UIScrollView *baseScrollView;

@property (nonatomic, assign) CGFloat statusViewSingleLineHeight;

//客户级视图图片
@property (weak, nonatomic) IBOutlet UIImageView *customerViewEntery;
//客户级视图图片高度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *customerViewHeight;
//客户级视图距离顶部高度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *customerViewTop;
//客户级视图点击事件
@property (nonatomic, strong) UITapGestureRecognizer *customerTap;

@property (nonatomic, strong) NewHomeCustomerViewModel *customerModel;

//网络请求计数器
@property (nonatomic, assign) NSInteger networkCount;

@end

@implementation NewLoveMarketingHomewController

static NSString *homeCarousIdentify = @"homeCarousIdentify";
static NSString *homeMarkIdentify = @"homeMarkIdentify";
static NSString *homeStatusIdentify = @"homeStatusIdentify";

- (instancetype)init {
    
    self = [super init];
    
    if (self) {
        NSBundle *bundle = [self getBundle];
        UIStoryboard *story = [UIStoryboard storyboardWithName:@"ZPaiyingxiao" bundle:bundle];
        self = [story instantiateViewControllerWithIdentifier:@"NewLoveMarketingHomewController"];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"爱营销";
    self.navigationController.navigationBar.titleTextAttributes=
    @{NSForegroundColorAttributeName:[UIColor whiteColor]};


    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:NMarketLoginStatus] isEqualToString:@"0"]) {
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    if (iSEESCREEN_WIDTH == 414) {
        
        _statusViewSingleLineHeight = iSEESCREEN_WIDTH / 4 / 93 * 93;
        
    }else {
        
        _statusViewSingleLineHeight = iSEESCREEN_WIDTH / 4 / 93 * 59;
    }
    
    [self addPagerView];//轮播图

    [self addPageControl]; //轮播图
    
    [self addStatusView]; //九宫格
    
    [self addOtherPush]; //统计报表
    
    [self addMarkView];
    
    //隐藏客户级视图入口
    [self customerViewHidden];
    
    //设置导航栏颜色
    if (self.navigationController) {
        
        self.navigationController.navigationBar.translucent = NO;
        self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
        [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

       self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"1B82D1"];
        
    }
    

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] bk_initWithImage:[self getImageFromBundle:@"open"] style:UIBarButtonItemStylePlain handler:^(id sender) {
        [self showMoreMenu]; //右上角
    }];
    
    
    
    _baseScrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        self.networkCount = 3;
        
        [self getCarouselList];
        
        [self getStatusAndLabel];
        
        [self getCustomerModel];
    }];

    _customerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(customerViewTouch:)];
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [_baseScrollView.mj_header beginRefreshing];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
}

- (void)reloadAllDatas {
    
    [_baseScrollView.mj_header beginRefreshing];
}


- (void)showMoreMenu {

    NSMutableArray *kxItems = [NSMutableArray array];
//
//    KxMenuItem * menuItem1 = [KxMenuItem menuItem:@"扫一扫"image:[self getImageFromBundle:@"flip"] target:self action:@selector(QRcodeshowAction)];
//    [kxItems addObject:menuItem1];
    
    KxMenuItem * menuItem2 = [KxMenuItem menuItem:@"刷新"
                                           image:[self getImageFromBundle:@"refresh"]
                                          target:self
                                          action:@selector(reloadAllDatas)];
    [kxItems addObject:menuItem2];
    
    KxMenuItem * menuItem3 = [KxMenuItem menuItem:@"摇商机"
                                            image:[self getImageFromBundle:@"Shake"]
                                           target:self
                                           action:@selector(goShake)];
    [kxItems addObject:menuItem3];
    
    [KxMenu setTitleFont:[UIFont fontWithName:@"HelveticaNeue" size:15]];

    
    OptionalConfiguration  abcd =   {
        .arrowSize = 9,  //指示箭头大小
        .marginXSpacing = 5,  //MenuItem左右边距
        .marginYSpacing = 7,  //MenuItem上下边距
        .intervalSpacing = 10,  //MenuItemImage与MenuItemTitle的间距
        .menuCornerRadius = 7,  //菜单圆角半径
        .maskToBackground = true,  //是否添加覆盖在原View上的半透明遮罩
        .shadowOfMenu =false,  //是否添加菜单阴影
        .hasSeperatorLine = true,  //是否设置分割线
        .seperatorLineHasInsets =NO,  //是否在分割线两侧留下Insets
        .menuBackgroundColor = {.R = 1, .G = 1, .B = 1},  //menuItem背景字体颜色
        
    };
    
    [KxMenu showMenuInView:self.view fromRect:CGRectMake(iSEESCREEN_WIDTH - 60 , 0, 60, 5) menuItems:kxItems withOptions:abcd];
}


- (void)addStatusView {
    
    UICollectionViewFlowLayout *statusLayout = [[UICollectionViewFlowLayout alloc] init];
    statusLayout.minimumInteritemSpacing = 0;
    statusLayout.minimumLineSpacing = 0;
    statusLayout.itemSize = CGSizeMake(iSEESCREEN_WIDTH / 4, _statusViewSingleLineHeight);
    
    _statusView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, iSEESCREEN_WIDTH, 187)collectionViewLayout:statusLayout];

    _statusView.backgroundColor = [UIColor whiteColor];
    _statusView.delegate = self;
    _statusView.dataSource = self;
    [_statusView registerNib:[self getNibFromBundle:@"NewLoveMarkingStatusCell"] forCellWithReuseIdentifier:homeStatusIdentify];
    [self.statusBackView addSubview:_statusView];
}

- (void)addMarkView {
    UICollectionViewFlowLayout *markLayout = [[UICollectionViewFlowLayout alloc] init];
    markLayout.minimumInteritemSpacing = 10;
    markLayout.minimumLineSpacing = 10;
    markLayout.itemSize = CGSizeMake(133, 75);
    markLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    _markCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 10, iSEESCREEN_WIDTH, 75)collectionViewLayout:markLayout];
    _markCollectionView.backgroundColor = [UIColor whiteColor];
    _markCollectionView.showsHorizontalScrollIndicator = NO;
    _markCollectionView.contentInset = UIEdgeInsetsMake(0, 10, 0, 10);
    _markCollectionView.delegate = self;
    _markCollectionView.dataSource = self;
    [_markCollectionView registerNib:[self getNibFromBundle:@"NewLoveMarketingMarkCell"] forCellWithReuseIdentifier:homeMarkIdentify];
    [self.markBackView addSubview:_markCollectionView];
}

- (void)addPagerView {

    
    _carousePageView = [[TYCyclePagerView alloc] init];
    _carousePageView.isInfiniteLoop = YES;
    _carousePageView.autoScrollInterval = 10.0;
    _carousePageView.dataSource = self;
    _carousePageView.delegate = self;
    [_carousePageView registerNib:[self getNibFromBundle:@"NewLoveMarketingTopCarouselCell"] forCellWithReuseIdentifier:homeCarousIdentify];
    [self.carouseBackView addSubview:_carousePageView];
    
}

- (void)addPageControl {
    _carousePageCtrl = [[TYPageControl alloc] init];
    _carousePageCtrl.currentPageIndicatorSize = CGSizeMake(8, 8);
    _carousePageCtrl.pageIndicatorTintColor = [UIColor colorWithHexString:@"EAECEF"];
    _carousePageCtrl.currentPageIndicatorTintColor = [UIColor colorWithHexString:@"169BD5"];
    [self.carouseBackView addSubview:_carousePageCtrl];
    
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    _carousePageView.frame = CGRectMake(0, 0, iSEESCREEN_WIDTH, 155 - 10);
    _carousePageCtrl.frame = CGRectMake(0, CGRectGetHeight(_carousePageView.frame), CGRectGetWidth(_carousePageView.frame), 10);
    
}



#pragma mark 轮播图代理

- (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
    if (pageView == _carousePageView) {
        return _carouseList.count;
    }else if (pageView == _markPageView) {
        
        return _homeModel.labelList.count;
    }else {
        return 0;
    }
}

- (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
    
    if (pagerView == _carousePageView) {
        NewLoveMarketingTopCarouselCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:homeCarousIdentify forIndex:index];
        
        cell.model = _carouseList[index];
        cell.delegate = self;
        return cell;
    }else if (pagerView == _markPageView) {
        NewLoveMarketingMarkCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:homeMarkIdentify forIndex:index];
        cell.model = _homeModel.labelList[index];
        return cell;
    }else {
        return [UICollectionViewCell alloc];
    }
    
    
}

- (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
    if (pageView == _carousePageView) {
        TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
        layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame), CGRectGetHeight(pageView.frame));
        layout.itemSpacing = 0;
        layout.itemHorizontalCenter = YES;
        return layout;
    }else if (pageView == _markPageView) {
        TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
        layout.itemSize = CGSizeMake(133, 75);
        layout.itemSpacing = 10;
        layout.itemHorizontalCenter = NO;
        return layout;
    }else {
        return [[TYCyclePagerViewLayout alloc]init];
    }
}

- (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
    if (pageView == _carousePageView) {
        
        _carousePageCtrl.currentPage = toIndex;

    }else if (pageView == _markPageView) {
        
        _markPageCtrl.currentPage = toIndex;
    }

}

- (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(nonnull __kindof UICollectionViewCell *)cell atIndex:(NSInteger)index {
    if (pageView == _carousePageView) {
        NewHomeCarouselModel *model = _carouseList[index];
        if ([model.indexType isEqualToString:@"send"]) {
            [self pushNextCtrl:@"544" Type:@"order" Title:@"未派发"];
        }else if ([model.indexType isEqualToString:@"call"]) {
            [self pushNextCtrl:@"529" Type:@"order" Title:@"已联系"];
        }
    
        
    }else if (pageView == _markPageView) {
        
        NewHomeMarkModel *model = _homeModel.labelList[index];
        ZSBWorkOrderViewController *ctrl = [[ZSBWorkOrderViewController alloc] init];
        ctrl.title = model.labelName;
        ctrl.labelId = model.labelId;
        ctrl.reload = @"reload";
        ctrl.type = @"1";
        [self pushToNextController:self.navigationController NextController:ctrl];
    }
}

#pragma NewLoveMarketingTopCarouselCellDelegate
- (void)newLoveMarketingTopCarouselCell:(NewLoveMarketingTopCarouselCell *)cell model:(NewHomeCarouselModel *)model {
    if ([model.indexType isEqualToString:@"send"]) {
        [self pushNextCtrl:@"544" Type:@"order" Title:@"未派发"];
    }else if ([model.indexType isEqualToString:@"call"]) {
        [self pushNextCtrl:@"529" Type:@"order" Title:@"已联系"];
    }
}


#pragma mark collectionViewDelegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (_statusView == collectionView) {
        return _homeModel.statusList.count;
    }else if (_markCollectionView == collectionView) {
        return _homeModel.labelList.count;
    }else {
        return 0;
    }
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (_statusView == collectionView) {
        NewLoveMarkingStatusCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:homeStatusIdentify forIndexPath:indexPath];
        cell.model = [NewHomeGroupEntranceModel yy_modelWithDictionary: _homeModel.statusList[indexPath.row]];
        return cell;
    }else if (_markCollectionView == collectionView) {
        NewLoveMarketingMarkCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:homeMarkIdentify forIndexPath:indexPath];
        cell.model = [NewHomeMarkModel yy_modelWithDictionary: _homeModel.labelList[indexPath.row]];
        return cell;
    }else {
        return [[UICollectionViewCell alloc] init];
    }
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (_statusView == collectionView) {
        NewHomeGroupEntranceModel *model = _homeModel.statusList[indexPath.row];
        [self pushNextCtrl:model.logId Type:model.type Title:model.logName];
    }else if (_markCollectionView == collectionView) {
        NewHomeMarkModel *model = _homeModel.labelList[indexPath.row];
        ZSBWorkOrderViewController *ctrl = [[ZSBWorkOrderViewController alloc] init];
        ctrl.title = model.labelName;
        ctrl.labelId = model.labelId;
        ctrl.reload = @"reload";
        ctrl.type = @"1";
        [self pushToNextController:self.navigationController NextController:ctrl];
    }
}



#pragma mark 数据重载

- (void)reloadOtherData {
    if (_homeModel) {
        
        for (int i = 0; i < _homeModel.orderTradeList.count; i++) {
            NewHomeGroupEntranceModel *model =  [NewHomeGroupEntranceModel yy_modelWithDictionary: _homeModel.orderTradeList[i]];
            UILabel *title = [self.view viewWithTag:200 + i];
            UILabel *totalLab = [self.view viewWithTag:300 + i];
            NSLog(@"%@", model);
            title.text = model.total;
            totalLab.text = model.logName;
            
            UIView *backView= [self.view viewWithTag:400 + i];
            [backView bk_whenTapped:^{
                [self pushNextCtrl:model.logId Type:model.type Title:model.logName];
            }];
        }
        
        [_markCollectionView reloadData];
        
        if (_homeModel.statusList.count % 4 == 0) {
            _statusBackViewHeight.constant = _statusViewSingleLineHeight * _homeModel.statusList.count / 4;
            _statusView.frame = CGRectMake(0, 0, iSEESCREEN_WIDTH, _statusViewSingleLineHeight * _homeModel.statusList.count / 4);
        }else {
            _statusBackViewHeight.constant = _statusViewSingleLineHeight * (_homeModel.statusList.count / 4 + 1);
            _statusView.frame = CGRectMake(0, 0, iSEESCREEN_WIDTH, _statusViewSingleLineHeight * (_homeModel.statusList.count / 4 + 1));
        }
        [_statusView reloadData];
    }
}

#pragma mark 页面统一转跳

- (void)pushNextCtrl:(NSString *) logId Type:(NSString *)type Title:(NSString *) title{
    if ([type isEqualToString:@"order"]) {
        ZSBWorkOrderViewController *ctrl = [[ZSBWorkOrderViewController alloc] init];
        ctrl.title = title;
        ctrl.logId = logId;
        ctrl.reload = @"reload";
        [self pushToNextController:self.navigationController NextController:ctrl];
    }else if ([type isEqualToString:@"trade"]) {
        NewOrdorListViewController *ctrl = [[UIStoryboard storyboardWithName:@"ZPaiyingxiao" bundle:[NSBundle bundleWithBundleName:@"NewMarketLib" podName:@"NewMarketLib"]] instantiateViewControllerWithIdentifier:@"NewOrdorListViewController"];
        ctrl.logId = logId;
        [self pushToNextController:self.navigationController NextController:ctrl];
    }
}

- (void)addOtherPush {
    //统计报表
    [self.statisticalReport bk_whenTapped:^{
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"该功能暂不开放" preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
        }]];
        [self presentViewController:alert animated:YES completion:nil];
    }];
    
    //微培训
    [self.smallTraining bk_whenTapped:^{
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请移步消息中心" preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }]];
        [self presentViewController:alert animated:YES completion:nil];
        
    }];
    
    //易问
    [self.easyAsking bk_whenTapped:^{
        NSString *mobile = [[NSUserDefaults standardUserDefaults] valueForKey:@"username"];
        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"eAskAppAsker://"]])  {
            NSString *openURL =    [NSString stringWithFormat:@"eAskAppAsker://systemid=iSee&phoneno=%@",mobile];
            [[UIApplication  sharedApplication] openURL:[NSURL URLWithString:openURL]];
        }else {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您尚未安装易问,请先安装易问" preferredStyle:UIAlertControllerStyleAlert];
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://eask.zjtelecom.com.cn:9090/downloadapp/AppStoreFrontier/"]];
            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
            [self presentViewController:alert animated:YES completion:nil];
        }
    }];
    
}

//二维码
//-(void)QRcodeshowAction{
//
//    ErweimaViewController *erwei =[[ErweimaViewController alloc] init];
//    erwei.title = @"二维码扫描";
//    [self pushToNextController:self.navigationController NextController:erwei];
//
//}

//快捷办理
- (IBAction)fastProcessingButtonAction:(id)sender {
    ZPjiugonggeViewController *jiugonggeView =[[ZPjiugonggeViewController alloc] init];

    jiugonggeView.title=@"快捷办理";
    [self pushToNextController:self.navigationController NextController:jiugonggeView];
}

//商机录入
- (IBAction)businessEntryButtonAction:(id)sender {
    NewHomeWebViewController *receiptView = [[NewHomeWebViewController alloc] init];
    receiptView.title = @"商机录入";
    [self pushToNextController:self.navigationController NextController:receiptView];
    
}


#pragma mark 网络请求

//顶部轮播图
- (void)getCarouselList {
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    
    
    [iSeeNetworkRequest getWithHeaderUrl:[NSString stringWithFormat:@"%@%@", NMarketMainUrl, GetNMarketHomeTopIndex] params:parmas success:^(id object) {
        [self.carouseList removeAllObjects];
        if ([object[@"code"] integerValue] == 200) {
            
            [self.carouseList addObjectsFromArray:[NewHomeCarouselModel mj_objectArrayWithKeyValuesArray:object[@"body"]]];
            self.carousePageCtrl.numberOfPages = self.carouseList.count;
            [self.carousePageView reloadData];
            
        }else{
            
            [SVProgressHUD showErrorWithStatus:object[@"msg"]];
            
        }
        self.networkCount--;
    } failure:^(NSError *error) {
        self.networkCount--;
        [SVProgressHUD dismiss];
    }];

}

- (void)getStatusAndLabel {
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    
    [iSeeNetworkRequest getWithHeaderUrl:[NSString stringWithFormat:@"%@%@", NMarketMainUrl, GetNMarketHomeHomeStatusAndLabel] params:parmas success:^(id object) {
        if ([object[@"code"] integerValue] == 200) {
            
            self.homeModel = [NewLoveMarketingHomeModel mj_objectWithKeyValues:object[@"body"]];
            
            [self reloadOtherData];
            
        }else{
            
            [SVProgressHUD showErrorWithStatus:object[@"msg"]];
            
        }
        self.networkCount--;
    } failure:^(NSError *error) {
        self.networkCount--;
    }];
}

#pragma mark 网络请求计数器处理页面请求
- (void)setNetworkCount:(NSInteger)networkCount {
    
    _networkCount = networkCount;
    if (_networkCount == 0) {
        [self.baseScrollView.mj_header endRefreshing];
    }
    
}

#pragma mark 转跳下级页面

- (void)pushToNextController: (UINavigationController *) nav NextController:(UIViewController *) ctrl {

    [nav pushViewController:ctrl animated:YES];

}

- (void)goShake {
//    ShakeViewController *shake = [[ShakeViewController alloc] init];
//    [self.navigationController pushViewController:shake animated:YES];
//
//    FiftyMeterCommercialOpportunityViewController *fifty = [[UIStoryboard storyboardWithName:@"ZPaiyingxiao" bundle:nil] instantiateViewControllerWithIdentifier:@"FiftyMeterCommercialOpportunityViewController"];
//    [self.navigationController pushViewController:fifty animated:YES];
    
}



#pragma mark 客户级视图相关数据

- (void)getCustomerModel {
    
    [iSeeNetworkRequest getWithHeaderUrl:[NSString stringWithFormat:@"%@%@", NMarketMainUrl,MarketHomeCustomer] params:nil success:^(id object) {
        
        self.customerModel = [NewHomeCustomerViewModel mj_objectWithKeyValues:object[@"body"]];
        
        if (self.customerModel.authFlag) {
            [self customerViewShow];
        }else {
            [self customerViewHidden];
        }
        self.networkCount--;
    } failure:^(NSError *error) {
        self.networkCount--;
    }];
    
}


- (void)customerViewShow {
    
    _customerViewEntery.hidden = NO;
    _customerViewHeight.constant = iSEESCREEN_WIDTH * 75 / 375;
    _customerViewTop.constant = 8;
    _customerViewEntery.userInteractionEnabled = YES;
    [_customerViewEntery sd_setImageWithURL:[NSURL URLWithString:_customerModel.imageUrl]];
    [_customerViewEntery addGestureRecognizer:_customerTap];
    
}

- (void)customerViewHidden {
    
    _customerViewEntery.hidden = YES;
    _customerViewTop.constant = 0;
    _customerViewHeight.constant = 0;
    [_customerViewEntery removeGestureRecognizer:_customerTap];
    
}

- (void)customerViewTouch:(UITapGestureRecognizer *) tap {
    
//    [[iSeeBuriedPoint defaultiSeeBuriedPoint] postiSeeBuriedPointByAccessId:self.customerModel.systemResourceRowId];
    
    NewMarketWebViewController *receiptView = [[NewMarketWebViewController alloc] init];
    
    ISeeUserInfoModel *userInfo = [ISeeUserInfoModel mj_objectWithKeyValues:[[[NSUserDefaults standardUserDefaults] objectForKey:NMarketUserInfo] mj_JSONObject]];
    
    receiptView.loadUrl = [[self.customerModel.gotoCustLitUrl stringByReplacingOccurrencesOfString:@"${session}" withString:[[NSUserDefaults standardUserDefaults] objectForKey:NMarketUserSession]] stringByReplacingOccurrencesOfString:@"${userId}" withString:userInfo.userId];
    [self pushToNextController:self.navigationController NextController:receiptView];
}







#pragma mark 懒加载

- (NSMutableArray *)carouseList {
    if (!_carouseList) {
        _carouseList = [NSMutableArray array];
    }
    return _carouseList;
}

- (NewLoveMarketingHomeModel *)homeModel {
    if (!_homeModel) {
        _homeModel = [[NewLoveMarketingHomeModel alloc] init];
    }
    return _homeModel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
